package br.spring;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class Audience {

	@Pointcut("execution(* br.spring.Performer.perform(..))")
	public void performance() {
	}

	/*
	 * @Around("performance()") public void watchPerformance(ProceedingJoinPoint
	 * joinpoint){ try { takeSeats(); turnOffCellPhones(); long
	 * start=System.currentTimeMillis(); joinpoint.proceed(); long
	 * end=System.currentTimeMillis(); applaud();
	 * System.out.println("The performance took "+(end-start)+
	 * " milliseconds."); } catch(Throwable t){
	 * System.out.println("Boo! We want our money back!"); } }
	 */

	@Before("performance()")
	public void takeSeats() {
		System.out.println("The audience is taking theirs seats.");
	}

	@Before("performance()")
	public void turnOffCellPhones() {
		System.out.println("The audience is turning off theirs cell phones.");
	}

	@After("performance()")
	public void applaud() {
		System.out.println("CLAP CLAP CLAP CLAP CLAP CLAP CLAP");
	}

	@AfterThrowing("performance()")
	public void demandRefund() {
		System.out.println("Boo! We want our money back!");
	}

}
